import abc
from datetime import datetime
from threading import Thread


class Notifier(metaclass=abc.ABCMeta):
    def __init__(self,*,debug=False,text_pattern:str='') -> None:
        self.debug=debug
        if not text_pattern:
            self.text_pattern='现在是{time}'
        else:
            self.text_pattern=text_pattern
    
    def log(self,*args):
        if not self.debug:
            return
        print(*args)
    
    def format_msg(self):
        now=datetime.now()
        hour=now.hour
        minute=now.minute
        return self.text_pattern.format(time=f'{hour}点{minute}分')
    
    def __call__(self, *args) :
        self.notify(*args)

    @abc.abstractclassmethod
    def notify(self):
        pass

    def notify_async(self):
        Thread(target=self.notify).start()


